﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimaryAlgorithm.Generate
{
    class MainProject
    {
        /// <summary>
        /// 杨辉三角
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            IList<IList<int>>  s = Generate(5);
            foreach (var item in s)
            {
                foreach (var item1 in item)
                {
                    Console.WriteLine(item1);
                }
                Console.WriteLine("-------------------");
            }
            Console.ReadKey();
        }

        public static IList<IList<int>> Generate(int numRows)
        {
            IList<IList<int>> lists = new List<IList<int>>();
            List<int> list1 = new List<int>();
            list1.Add(1);
            lists.Add(list1);
            for (int i = 1; i < numRows; i++)
            {
                List<int> list = new List<int>();
                if ((i+1)-2>0)
                {
                    for (int j = 0; j < lists[i-1].Count-1; j++)
                    {
                        list.Add(lists[i - 1][j]+ lists[i - 1][j+1]);
                    }
                }
                list.Insert(0,1);
                list.Add(1);
                lists.Add(list);
            }
            return lists;
        }
    }
}
